//
//  HSYProgressSliderView.m
//  高仿暴走斗图
//
//  Created by key on 16/5/10.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYProgressSliderView.h"

@interface HSYProgressSliderView ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIView *sliderView;
@property (nonatomic, strong) UILabel *percentageLabel;

@end

@implementation HSYProgressSliderView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.imageView = [NSObject createImgWithImage:[UIImage imageNamed:@"img_slider"]
                                               hImage:[UIImage imageNamed:@"img_slider"]
                                        clipsToBounds:YES
                                              vcModel:UIViewContentModeScaleToFill];
        [self addSubview:self.imageView];
        self.imageView.clipsToBounds = YES;
        CGFloat offset_img = 5.0f;
        self.imageView.frame = CGRectMake(offset_img, 5, self.viewWidth - offset_img *2, self.viewHeight/2);
        
        NSString *percentageString = [NSString stringWithFormat:@"%f", self.percentage];
        NSString *symbol = @"%";
        
        _percentage = 0.0f;
        self.percentageLabel = [NSObject createLabelWithText:[NSString stringWithFormat:@"%@%@", percentageString, symbol]
                                                   textColor:[UIColor whiteColor] bkColor:[UIColor clearColor]
                                                        font:HSYFONTSIZE(12)
                                               textAlignment:NSTextAlignmentCenter];
        self.percentageLabel.frame = self.imageView.bounds;
        [self.imageView addSubview:self.percentageLabel];
        
        self.sliderView = [NSObject createViewWithBgColor:[UIColor whiteColor]];
        
        self.sliderView.clipsToBounds = YES;
        [self.sliderView.layer setCornerRadius:5.0f];
        [self addSubview:self.sliderView];
        CGFloat offset_view = 9.0f;
        CGFloat offset_view_y = self.imageView.viewMidY + 5;
        self.sliderView.frame = CGRectMake(offset_view, offset_view_y, self.viewWidth -offset_view*2, self.viewHeight - offset_view_y - 2);
        
        _sliderMidY = self.sliderView.viewMidY;
        _sliderY = self.sliderView.viewX;
        _sliderX = self.sliderView.viewY;
        _sliderSize = self.sliderView.viewSize;
    }
    return self;
}

- (void)setPercentage:(CGFloat)percentage {
    
    _percentage = percentage;
    NSString *percentageString = [NSString stringWithFormat:@"%f", percentage];
    NSString *symbol = @"%";
    self.percentageLabel.text = [NSString stringWithFormat:@"%@%@", percentageString, symbol];
}

@end
